
package com.voicecheck.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aris.voicechecking.R;
import com.voicecheck.v2.model.HistoryLessonModel;

public class DayResultAdapter extends BaseAdapter {

    protected List<HistoryLessonModel> listdata;

    public DayResultAdapter(List<HistoryLessonModel> data) {
        listdata = data;
    }

    @Override
    public int getCount() {
        return listdata.size();
    }

    @Override
    public Object getItem(int position) {
        return listdata.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder vh;
        Context ct = parent.getContext();

        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(
                    R.layout.item_day_report, parent, false);

            vh = new ViewHolder();
            vh.title = (TextView)convertView.findViewById(R.id.day_report_title);
            vh.done_button = (ImageView)convertView.findViewById(R.id.day_report_done_ic);
            vh.state_button = (ImageView)convertView.findViewById(R.id.day_report_status_ic);

            convertView.setTag(vh);
        } else {
            vh = (ViewHolder)convertView.getTag();
        }

        HistoryLessonModel lessonHistory = (HistoryLessonModel)getItem(position);

        vh.title.setText(ct.getResources().getString(R.string.week) + lessonHistory.getWeek()
                + " - " + ct.getResources().getString(R.string.day) + lessonHistory.getDay() + " ("
                + (lessonHistory.getLesson() > 3 ? 2 : 1) + "-"
                + ((lessonHistory.getLesson() - 1) % 3 + 1) + ")");
        vh.title.setTextColor(Color.BLACK);

        vh.done_button.setVisibility(View.GONE);

        if (lessonHistory.getLast_done() == 1) {
            vh.state_button.setImageResource(R.drawable.answer_pass);
        } else
            vh.state_button.setImageResource(R.drawable.answer_fail);

        convertView.setBackgroundColor(Color.WHITE);

        return convertView;
    }

    static class ViewHolder {
        TextView title;

        ImageView done_button;

        ImageView state_button;
    }

}
